package servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Online;
import dao.onlinedeo;

public class YesrOnlineServlet extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {  
        this.doPost(request, response);  
    }  
    public void doPost(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {
    	
    	//获取时间，并格式化指定日期格式
    	Date dNow = new Date();   //当前时间
    	Date dBefore = new Date();
    	Calendar calendar = Calendar.getInstance(); //得到日历
    	calendar.setTime(dNow);//把当前时间赋给日历
    	calendar.add(Calendar.DAY_OF_MONTH, -1);  //设置为前一天
    	dBefore = calendar.getTime();   //得到前一天的时间

    	SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); //设置时间格式
    	String defaultStartDate = sdf.format(dBefore);    //格式化前一天
    	
    	onlinedeo db = new onlinedeo();  
    	 String sql = " select area,company_num,monitor_num,online_num,offline_num,equ_date,online_rate from online where  equ_date='"+defaultStartDate+"'"; 
        ArrayList<Online> list = null;
		try {
			list = db.getOnlineList(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
        request.setAttribute("list", list);  
        request.getRequestDispatcher("yesrterday.jsp").forward(request, response);  
    }  
}
